<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed!');

if ( ! function_exists('thumbnail'))
{
	function thumbnail($image, $width = 100, $height = 100)
	{
		$CI =& get_instance();
		$module = $CI->router->fetch_module();
		return site_url("$module/thumb_{$width}x{$height}/$image");
	}
}

if ( ! function_exists('css_theme'))
{
	function css_theme($file)
	{
		$CI =& get_instance();
		return site_url($CI->router->fetch_module().'/themestyle/'.$file);
	}
}

if ( ! function_exists('img_theme'))
{
	function img_theme($file)
	{
		$CI =& get_instance();
		return site_url($CI->router->fetch_module().'/themeimage/'.$file);
	}
}

if ( ! function_exists('js_theme'))
{
	function js_theme($file)
	{
		$CI =& get_instance();
		return site_url($CI->router->fetch_module().'/themescript/'.$file);
	}
}

if ( ! function_exists('font_theme'))
{
	function font_theme($file)
	{
		$CI =& get_instance();
		return site_url($CI->router->fetch_module().'/themefont/'.$file);
	}
}

if ( ! function_exists('slugify'))
{
	function slugify($text, $junction = '_')
	{
		$text = preg_replace('~[^\\pL\d]+~u', $junction, $text);
		$text = trim($text, '-');
		$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
		$text = strtolower($text);
		$text = preg_replace('~[^-\w]+~', '', $text);
		
		if (empty($text)) 
			return 'n-a';

		return $text;
	}
}



if ( ! function_exists('domain_url'))
{
	function domain_url()
	{
		$CI =& get_instance();
		return preg_replace("/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/","$1", $CI->config->slash_item('base_url'));	
	}
}

if ( ! function_exists('template'))
{
	function template($name)
	{
		$CI =& get_instance();
		$CI->db->from('templates');
		$CI->db->where('tpl_name', $name);
		$query = $CI->db->get();

		if ($query->num_rows() > 0)
			return $query->row()->tpl_content;

		return '';
	}
}